package com.ax.api.route.base.drugadministration;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

import com.ax.api.route.util.RouteConfig;

@Controller
@RequestMapping("/drugAdministrationManager")
public class DrugAdministrationManagerRoute {
	 @Autowired
	 LoadBalancerClient loadBalancerClient;
	 @Autowired
	 RestTemplate restTemplate;
	
   /**
	 * 菜单页面的跳转
	 */
	@GetMapping("/sys/drugAdministrationManager")
	String drugAdministration(Model model) {
		String url = geturl("/sys/drugAdministrationManager");
		return restTemplate.getForObject(url, String.class);
	}
	
	/**
	 * queryDrugAdministrationManager
	 * remote_base
	 * 药监查询(模块:药监人员)*包含该人的药监部门信息
	 */  
	@GetMapping("/queryDrugAdministrationManager")
	String queryDrugAdministrationManager(@RequestParam Map<String,Object> map) {
		String value = "?drugManagerId={drugManagerId}&drugDepId={drugDepId}&offset={offset}&limit={limit}";
		String url = geturl("/sys/drugAdministrationManager/queryDrugAdministrationManager") + value;
		return restTemplate.getForObject(url, String.class,map);
	}
	
	/**
	 * add
	 * remote_base
	 * 药监增加(模块:药监人员)*跳转增加页面
	 */   
	@GetMapping("/add/drugAdministrationManager")
	public String addDrugAdministration(){
		String url = geturl("/sys/drugAdministrationManager/add");
		return restTemplate.getForObject(url, String.class);
  }
   /**
	 * insertDrugManager
	 * remote_base
	 * 药监增加(模块:药监人员)*跳转增加页面
	 */
    @GetMapping("/insertDrugManager")
	String insertDrugManager(@RequestParam Map<String,Object> map) {
		String value = "?drugManagerName={drugManagerName}&drugDepId={drugDepId}&drugDepName={drugDepName}&post={post}&empno={empno}&personId={personId}&sex={sex}&birth={birth}&entryTime={entryTime}&phone={phone}&address={address}&remarks={remarks}&flag={flag}";
		String url = geturl("/sys/drugAdministrationManager/insertDrugManager") + value;
		return restTemplate.getForObject(url, String.class,map);
	}
    
    /**
	 * edit
	 * remote_base
	 * 药监修改(模块:药监人员)*跳转修改页面
	 */ 
    @GetMapping("/edit/drugAdministrationManager")
	public String addDrugAdministration(Long id){
    	String value = "/id=" + id;
		String url = geturl("/sys/drugAdministrationManager/edit") + value;
		return restTemplate.getForObject(url, String.class,id);
   }
	
	/**
	 * insertDrugManager
	 * remote_base
	 * 药监修改(模块:药监人员)
	 */
    @GetMapping("/updateDrugManager")
	String updateDrugManager(@RequestParam Map<String,Object> map) {
		String value = "?drugManagerName={drugManagerName}&drugManagerId={drugManagerId}&drugDepId={drugDepId}&drugDepName={drugDepName}&post={post}&empno={empno}&personId={personId}&sex={sex}&birth={birth}&entryTime={entryTime}&phone={phone}&address={address}&remarks={remarks}&flag={flag}";
		String url = geturl("/sys/drugAdministrationManager/updateDrugManager") + value;
		return restTemplate.getForObject(url, String.class,map);
	}
	
	/**
	 * updateState
	 * remote_base
	 * 药监修改(模块:药监人员)
	 */
    @GetMapping("/updateState")
	String updateState(@RequestParam Map<String,Object> map) {
		String value = "?parameter={parameter}&flag={flag}";
		String url = geturl("/sys/drugAdministrationManager/updateState") + value;
		return restTemplate.getForObject(url, String.class,map);
	}
	
	private String geturl(String path){
	 ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BASE_ROUTE);
	 StringBuffer bf = new StringBuffer("http://");
	 bf.append(serviceInstance.getHost());
	 bf.append(":");
	 bf.append(serviceInstance.getPort());
	 bf.append(path);
	 return bf.toString();
   }
}
